#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int timeRequiredToBuy(vector<int>& tickets, int k) {
        int n = tickets.size();
        int ret = 0;
        for (int i = 0; i < n; i++)
        {
            if (i <= k) ret += min(tickets[i], tickets[k]);
            else ret += min(tickets[i], tickets[k] - 1);

        }
        return ret;
    }
};